package com.youlai.boot.modules.game.controller;

import com.youlai.boot.common.result.Result;
import com.youlai.boot.modules.game.model.vo.GameUserStatisticsVO;
import com.youlai.boot.modules.game.service.GameUserStatisticsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 游戏用户统计控制器
 *
 * @author 有来技术团队
 */
@Tag(name = "06.游戏统计管理")
@RestController
@RequestMapping("/api/v1/game/statistics")
@RequiredArgsConstructor
public class GameUserStatisticsController {

    private final GameUserStatisticsService gameUserStatisticsService;

    @Operation(summary = "获取用户统计信息")
    @GetMapping("/user")
    public Result<GameUserStatisticsVO> getUserStatistics(
            @Parameter(description = "用户ID") @RequestParam(required = false) Long userId) {
        GameUserStatisticsVO statistics = gameUserStatisticsService.getUserStatistics(userId);
        return Result.success(statistics);
    }

    @Operation(summary = "获取用户每日游戏时长")
    @GetMapping("/daily-play-time")
    public Result<List<Map<String, Object>>> getDailyPlayTime(
            @Parameter(description = "用户ID") @RequestParam(required = false) Long userId) {
        List<Map<String, Object>> data = gameUserStatisticsService.getDailyPlayTime(userId);
        return Result.success(data);
    }

    @Operation(summary = "获取用户游戏时段分布")
    @GetMapping("/hourly-distribution")
    public Result<List<Map<String, Object>>> getHourlyDistribution(
            @Parameter(description = "用户ID") @RequestParam(required = false) Long userId) {
        List<Map<String, Object>> data = gameUserStatisticsService.getHourlyDistribution(userId);
        return Result.success(data);
    }

    @Operation(summary = "更新用户统计信息")
    @PostMapping("/update")
    public Result<Boolean> updateUserStatistics(
            @Parameter(description = "用户ID") @RequestParam(required = false) Long userId) {
        boolean result = gameUserStatisticsService.updateUserStatistics(userId);
        return Result.success(result);
    }
} 